function ok=checkSetupItem(itemName, itemValue)
%CHECKSETUPITEM shortdescr.
%
% Description
%
% Example: none
%
% See also getBlankSetup
% 
% @Author: Pete R Jones
% @Date: 22/01/10

    %----------------------------------------------------------------------
    % Parse & validate all input args
    p = inputParser;
    p.addRequired('itemName', @ischar);
    p.addRequired('itemValue');
    p.FunctionName = 'CHECKSETUPITEM';
    p.parse(itemName, itemValue);
    %----------------------------------------------------------------------
    
    % Initialise local variables
    ok=1;
    
    % Go!
    try
        switch itemName
            case 'homeDir'
                ok=local_checkHomeDir(itemValue);
            case 'lastUpdate'
                ok=local_checkLastUpdate(itemValue);
            case 'backupDir'
                ok=local_checkBackupDir(itemValue);
            case 'mode'
              	ok=local_checkMode(itemValue);
            case 'dbInfo'
                ok=local_checkDBInfo(itemValue);
            otherwise
                error('PsychTestRig:checkSetupItem:UnrecognisedItem', ['Unknown config property: "' itemName '".'])
        end
    catch
        ok=0;
    end
    
end

%%%%%%%%%%%%%%%%%%%%%%%
%%% LOCAL FUNCTIONS %%%
%%%%%%%%%%%%%%%%%%%%%%%

function ok=local_checkHomeDir(val)
    if exist(val,'dir')
        ok=1;
        return
    end
	ok = 0;
    %     warning('PsychTestRig:checkSetupItem:local_checkHomeDir','PsychTestRig:checkSetupItem:local_checkHomeDir: No checks performed.')
end

function ok=local_checkLastUpdate(val)
    
%     warning('PsychTestRig:checkSetupItem:local_checkLastUpdate','PsychTestRig:checkSetupItem:local_checkLastUpdate: No checks performed.')
%     fprintf('PsychTestRig:checkSetupItem:local_checkLastUpdate: %s\n','PsychTestRig:checkSetupItem:local_checkLastUpdate: No checks performed.')
    ok=1;
end

function ok=local_checkBackupDir(val)
    if exist(val,'dir')
        ok=1;
        return
    end
	ok = 0;
%     warning('PsychTestRig:checkSetupItem:local_checkBackupDir','PsychTestRig:checkSetupItem:local_checkBackupDir: No checks performed.')
end

function ok=local_checkMode(val)
    if any(strcmpi(val,{'lite','full'}))
        ok=1;
        return
    end
	ok = 0;
%     warning('PsychTestRig:checkSetupItem:local_checkMode','PsychTestRig:checkSetupItem:local_checkMode: No checks performed.')
end

function ok=local_checkDBInfo(val)
    if strcmpi(getPrefVal('mode'), 'full')
        warning('PsychTestRig:checkSetupItem:local_checkDBInfo','PsychTestRig:checkSetupItem:local_checkDBInfo: No checks performed.')
        ok=0;
        return
    end
    ok = 1;
end
            
            